//
// ***********************************************
// *    ___________   ___________  __      __    *
// *   |______  __/  /_____  ___/  \ \    / /    *
// *         / /          / /       \ \  / /     *
// *        / /          / /         \ \/ /      *
// *       / /          / /           \  /       *
// *      / /______    / /            / /        *
// *     /________/   /_/            /_/         *
// *                                             *
// ***********************************************
//
//   ThreadViewController.m
//   InterviewDemo
//   
//   Created  by wanmeizty on 20/12/2019
//   Modified by Tiyon  qq 897574226  
//   Copyright © 2019 wanmeizty. All rights reserved.
//   
   

#import "ThreadViewController.h"

@interface ThreadViewController ()

@end

@implementation ThreadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self test];
    
//    UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
//    [btn setTitle:@"点击" forState:UIControlStateNormal];
//    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:btn];
    // Do any additional setup after loading the view.
}

-(void)click:(UIButton *)btn{
//    [self viewframeandbounds];
//    [self setBoundsView];
//    [self setframeView];
//    [self setBoundsSizeView];
    [self setframeSIzeView];
}

// 旋转后 frame改变  bounds不变
-(void)transfromView{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 200, 200)];
    view.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view];
    
    UIView * subview = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 100, 40)];
    subview.backgroundColor = [UIColor greenColor];
    [view addSubview:subview];
    NSLog(@"%@--%@",NSStringFromCGRect(subview.bounds),NSStringFromCGRect(subview.frame));
    
    [UIView animateWithDuration:1 animations:^{
        subview.transform = CGAffineTransformMakeRotation(M_PI_4);
    }];
    
    NSLog(@"%@--%@",NSStringFromCGRect(subview.bounds),NSStringFromCGRect(subview.frame));
    
}

/*
setBounds中的(x,y)只改变自己的坐标系统，子View的bounds和frame并不会改变；
setBounds是修改自己坐标系的原点位置，进而影响到子View的显示位置；
bounds改变位置时，改变的是子视图的位置，自身没有影响，其实就是改变了自身的坐标系原点，默认原点在左上角。
 */
-(void)setBoundsView{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 200, 200)];
    view.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view];
    
    
    UIView * subview2 = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 100, 40)];
    subview2.backgroundColor = [UIColor blueColor];
    [view addSubview:subview2];
    
    UIView * subview = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 100, 40)];
    subview.backgroundColor = [UIColor greenColor];
    [view addSubview:subview];
    NSLog(@"%@--%@",NSStringFromCGRect(subview.bounds),NSStringFromCGRect(subview.frame));
    
    [UIView animateWithDuration:1 animations:^{
        [view setBounds:CGRectMake(-20, -20, 200, 200)];
    }];
    
    NSLog(@"%@--%@",NSStringFromCGRect(subview.bounds),NSStringFromCGRect(subview.frame));
    
}

/**
 我们改变了父View的frame,但是实际位置已经改变了，坐标系改变，子View的位置也改变了。但是子View的frame和bounds并没有改变。因为子View.origin是相对于父View的而言的，这并没有改变。
 */
-(void)setframeView{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 200, 200)];
    view.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view];
    
    
    UIView * subview2 = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 100, 40)];
    subview2.backgroundColor = [UIColor blueColor];
    [view addSubview:subview2];
    
    UIView * subview = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 100, 40)];
    subview.backgroundColor = [UIColor greenColor];
    [view addSubview:subview];
    NSLog(@"%@--%@",NSStringFromCGRect(subview.bounds),NSStringFromCGRect(subview.frame));
    
    [UIView animateWithDuration:1 animations:^{
        [view setFrame:CGRectMake(10, 10, 200, 200)];
    }];
    
    NSLog(@"%@--%@",NSStringFromCGRect(subview.bounds),NSStringFromCGRect(subview.frame));
    
}

/*
 更改bounds的大小，bounds的大小代表当前视图的长和宽，修改长宽后，中心点继续保持不变，长宽进行改变，通过bounds修改长宽就像是以中心点为基准点对长宽两边同时进行缩放。
 center是根据父容器的相对位置来计算的，无论是修改父容器的bounds还是自身的bounds，都不会改变center。况且使用bounds来缩放view，都是根据center中心点来缩放的，所以center不会改变。
setBounds也可以修改view的大小，进而修改frame。
 */
-(void)setBoundsSizeView{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 200, 200)];
    view.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view];
    
    
    UIView * subview2 = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 100, 40)];
    subview2.backgroundColor = [UIColor blueColor];
    [view addSubview:subview2];
    
    UIView * subview = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 100, 40)];
    subview.backgroundColor = [UIColor greenColor];
    [view addSubview:subview];
    NSLog(@"%@--%@",NSStringFromCGRect(subview.bounds),NSStringFromCGRect(subview.frame));
    
    [UIView animateWithDuration:1 animations:^{
        [view setBounds:CGRectMake(50, 100, 300, 300)];
    }];
    
    NSLog(@"%@--%@",NSStringFromCGRect(subview.bounds),NSStringFromCGRect(subview.frame));
    
}

/**
 使用frame改变view大小，center改变，因为缩放参考点为左上角。使用bounds改变view大小，center不变，因为缩放参考点为center。
 */
-(void)setframeSIzeView{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 200, 200)];
    view.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view];
    
    
    UIView * subview2 = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 100, 40)];
    subview2.backgroundColor = [UIColor blueColor];
    [view addSubview:subview2];
    
    UIView * subview = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 100, 40)];
    subview.backgroundColor = [UIColor greenColor];
    [view addSubview:subview];
    NSLog(@"%@--%@",NSStringFromCGRect(subview.bounds),NSStringFromCGRect(subview.frame));
    
    [UIView animateWithDuration:1 animations:^{
        [view setFrame:CGRectMake(50, 100, 300, 300)];
    }];
    
    NSLog(@"%@--%@",NSStringFromCGRect(subview.bounds),NSStringFromCGRect(subview.frame));
    
}

-(void)test{
    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"a---%@",[NSThread currentThread]);
    });
    NSLog(@"b---%@",[NSThread currentThread]);
    
    dispatch_queue_global_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    
    dispatch_async(queue, ^{
        NSLog(@"c---%@",[NSThread currentThread]);
    });
    dispatch_async(queue, ^{
        NSLog(@"d---%@",[NSThread currentThread]);
    });
    dispatch_sync(queue, ^{
        NSLog(@"e---%@",[NSThread currentThread]);
    });
    
    [self performSelector:@selector(ak) withObject:nil afterDelay:0];
    
    NSLog(@"g---%@",[NSThread currentThread]);
}

-(void)ak{
    NSLog(@"f---%@",[NSThread currentThread]);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
